package com.ltg.admin.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ltg.admin.domain.entity.SysUser;
import com.ltg.admin.param.LoginParam;
import com.ltg.admin.service.impl.SysUserServiceImpl;
import com.ltg.admin.utils.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/sys_user")
@Api(tags = "⽤户模块",value = "sys_user")
public class SysUserController {

    @Autowired
    private SysUserServiceImpl sysUserService;

    /**
     * 增加
     *
     * @param sysUser
     * @return
     */
    @PutMapping
    @ApiOperation("添加")
    public Result<Boolean> addUser(@RequestBody SysUser sysUser) {
        boolean save = sysUserService.save(sysUser);
        return Result.success(save);
    }

    /**
     * 分页查询
     *
     * @param pageIndex
     * @param pageSize
     * @return
     */
    @GetMapping("/query")
    @ResponseBody
    @ApiOperation("查询")
    public Result<Page<SysUser>> queryUserList(@RequestParam Integer pageIndex, @RequestParam Integer pageSize) {
        return sysUserService.queryUserList(pageIndex,pageSize);
    }

    /**
     * 根据id修改
     *
     * @param sysUser
     * @return
     */
    @PostMapping
    @ApiOperation("修改")
    public Result<Boolean> updateUser(@RequestBody SysUser sysUser) {
        boolean result = sysUserService.updateById(sysUser);
        return Result.success(result);
    }


    @PostMapping("/login")
    @ResponseBody
    @ApiOperation("登录")
    public Result login(@RequestBody LoginParam loginParam) {
        return this.sysUserService.login(loginParam);
    }


    @ResponseBody
    @ApiOperation("退出")
    public Result loginOut() {
        return this.sysUserService.loginOut();
    }





}
